<script setup lang="ts">
import CourseCard from "@/components/common/CourseCard.vue";
import {getMostNew} from "@/api/home";
import {onBeforeMount, Ref, ref} from "vue";

const mostNewData: Ref<Array<{
  id: string;
  clicks: number;
  courseLevel: number;
  discountPrice: number;
  courseCover: string;
  courseName: string;
}>> = ref([])
const getMostNewData = async () => {
  const res = await getMostNew({pageNum: 1, pageSize: 8})
  console.log(res)
  mostNewData.value = res.data.pageInfo.list
}
onBeforeMount(() => {
  getMostNewData()
})
</script>

<template>
  <div class="course">
    <div class="course-main">
      <div class="course-top">
        <div class="hot">
          <div class="hot-left">HOT</div>
          <div class="hot-right"></div>
        </div>
        <div class="title"><p>新上好课</p></div>
      </div>
      <div class="course-bottom">
        <ul>
          <li
              v-for="item in mostNewData"
              :key="item.id"
          >
            <CourseCard
                :count="item.clicks"
                :dengji="item.courseLevel"
                :price="item.discountPrice"
                :img-url="item.courseCover"
                :title="item.courseName"
            />
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<style scoped>
.course {
  width: 100%;

  .course-main {
    width: 1000px;
    margin: 0 auto;

    .course-top {
      display: flex;
      justify-content: start;
      height: 38px;

      .hot {
        width: 60px;
        display: flex;

        .hot-left {
          width: 100%;
          height: 38px;
          border-radius: 7px 0 7px 7px;
          background: linear-gradient(90deg, #ff727f 0%, #fc685c 100%);
          display: flex;
          justify-content: center;
          align-items: center;
        }

        .hot-right {
          width: 0;
          height: 0;
          border: 6px solid #fc685c;
          border-right-color: transparent;
          border-bottom-color: transparent;
        }
      }

      .title {
        width: 106px;
        display: flex;
        position: relative;
        text-align: center;

        p {
          width: 106px;
          font-size: 1.5em;
          font-weight: 600;
          z-index: 3;
        }

        &:after {
          content: '';
          display: inline-block;
          width: 106px;
          height: 13px;
          background: linear-gradient(90deg, #fbf84f 0%, #fea935 100%);
          position: absolute;
          bottom: 2px;
          border-radius: 5px;
        }
      }
    }

    .course-bottom {
      display: flex;
      justify-content: space-between;

      ul {
        display: flex;
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;

        li {
          margin-top: 20px;
        }
      }
    }
  }
}
</style>